package com.agree.util.excel.handlers.mapping;

import com.agree.util.excel.entity.InterfaceColMapEntity;
import com.agree.util.excel.entity.TableInfo;
import com.agree.util.excel.enums.*;

import java.io.IOException;
import java.util.List;

/**
 * Created by wangmu on 2017/12/4.
 */
public class QueryExamplePageMappingHandler extends MappingHandler {


    public QueryExamplePageMappingHandler(MappingConfig mappingConfig) {
        super(mappingConfig);
    }

    @Override
    protected void configure(TableInfo source) throws InstantiationException, IllegalAccessException, IOException {
        super.configure(source);
        startMapping()
                .reqParams().anyColumn(GetParamsType.FILE,source,this.getClass().getClassLoader().getResource("req").getPath()).everyone().setMsgtypeid(mappingConfig.getTranCode()+"."+ ParamConst.REQ_INFO.getCode()).setMsgtypename(mappingConfig.getComment() == null ? source.getComment()+getType().getValue() : mappingConfig.getComment())
                    .setColname("/"+ ParamConst.REQ_INFO.getName()+"/" + "#{humpName}").setColdesc("#{comment}").setColflag(ColumnFlag.F.name()).setColtype(ColumnType.TEXT_STRING.getValue()).setCollength("#{maxIntegerLength}")
                    .setColmapname("/#{humpName}").setColmust("#{must}").end();
    }

    @Override
    public List<InterfaceColMapEntity> mapProperties(TableInfo tableInfo) throws IllegalAccessException, InstantiationException, IOException {
        this.configure(tableInfo);
        InterfaceColMapEntity reqHeader = getReqHeader(tableInfo);
        List<InterfaceColMapEntity> reqParams = getReqParams(tableInfo);
        List<InterfaceColMapEntity> reqParamsPage = getReqParamsPage(tableInfo);
        InterfaceColMapEntity rspHeader = getRspHeader(tableInfo);
        List<InterfaceColMapEntity> rspParamsPage = getRspParamsPage(tableInfo);
        List<InterfaceColMapEntity> rspParams = getRspParams(tableInfo);

        reqParams.add(0,reqHeader);
        reqParams.addAll(reqParamsPage);
        reqParams.add(rspHeader);
        reqParams.addAll(rspParamsPage);
        reqParams.addAll(rspParams);

        insertOrderNum(reqParams);
        return reqParams;
    }

    @Override
    protected MappingType getType() {
        return MappingType.SIMPLE_QUERY_EXAMPLE;
    }

}
